<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拖动元素</title>
    <style>
        *{padding: 0px;margin: 0px;}
        div:first-of-type {
            background-color: red;
            width: 200px;
            
            line-height: 200px;
            text-align: center;
        }
        #img{
            width: 100px;
            height: 100px;
            object-fit: contain;
        }
    </style>
</head>
<body>
    <div id="div1">
        <p>元素终点</p>
    </div>
    <img id="img" src="./bluck/肥猪1.gif" alt="xxx" draggable="true">
</body>
<script>
let img=document.getElementById("img")
let div=document.getElementById("div1");
img.ondragstart=function(e){
    console.log(e.dataTransfer)
    console.log(e)
    e.dataTransfer.setData("text",e.target.id);//e.target.id(触发事件的对象的)
    console.log("aaa")
}
div.ondragover=function(e){//过去就触发
    e.preventDefault();//可以防止,默认不行
    console.log("Xxxx")
    return false
}
div.ondrop=function(e){
    e.preventDefault();
    console.log(e)
    div.innerText=e.dataTransfer.getData("text")//保存id
}
</script>
</html>